<script>
import ShoppingCart from './components/ShoppingCart.vue';

export default {
  name: "根组件",
  components: {
    ShoppingCart,
  },
  data() {
    return {
      goods: [
        { id: 1234, name: "Java从入门到放弃", price: 99, amount: 7 },
        { id: 2233, name: "Java从没入门到放弃", price: 88, amount: 4 },
        { id: 4321, name: "骗你学Vue之你行你上啊", price: 56, amount: 1 },
      ],
    };
  },
  methods: {
    add() {
      let x = {
        id: 5678,
        name: "睡佛是怎样炼成的",
        price: 108,
        amount: 12,
      };
      this.goods.push(x);
      console.log( this.$bus );
    }
  }
};
</script>

<template>
  <div class="wrapper">
    <ShoppingCart :goods="goods"></ShoppingCart>
    <button @click="add">添加新商品</button>
  </div>
</template>

<style>
.wrapper {
  width: 80%;
  margin: auto;
}
</style>
